<script setup lang="ts">
import {useRoute} from "vue-router";
import {onMounted, ref} from "vue";
import router from "@/router/index.js";
import {ElMessage} from "element-plus";
import {useGetWarehouseByIdAPI, useModifyWarehouseAPI} from "@/apis/warehouse.js";

const route = useRoute();

interface warehouseInfo{
  id:number,
  name:string,
  address:string,
  phone:string,
  contact:string,
  description:string,
}

const warehouse=ref<warehouseInfo>({
  id:0,
  name:"",
  address:"",
  phone:"",
  contact:"",
  description:""
});

onMounted(async () => {
  await useGetWarehouseByIdAPI(Number(route.params.id)).then(res=>{
    warehouse.value=res.data
  })
})

const updateWarehouseSummit=async ()=>{
  await useModifyWarehouseAPI(warehouse.value).then((res: any) => {
    if (res.code===200){
      ElMessage({
        type:'success',
        message:'修改成功',
      })
      router.push("/manage/warehouseManager");
    }
  })
}


</script>

<template>
  <div class="bread-container">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: `/` }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{path:`/manage/warehouseManager`}" >仓库列表</el-breadcrumb-item>
      <el-breadcrumb-item  >修改仓库</el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <div class="divTable">
    <table class="table">
      <tbody>
      <tr>
        <td class="tableTitle" colspan="4" >新增项目</td>
      </tr>
      <tr>
        <td style="width: 250px;height: 15px;text-align: center;background: #EFF6FF;color: #242424;font-family: 微软雅黑,serif">项目名称</td>
        <td style="width: 350px;height: 15px;   text-align: center  "><el-input  v-model="warehouse.name" /></td>
        <td style="width: 250px;height: 15px; text-align: center ;background: #EFF6FF"  >项目地址</td>
        <td style="width: 350px;height: 15px ; text-align: center   "><el-input  v-model="warehouse.address" /></td>
      </tr>
      <tr>
        <td style="width: 250px;height: 15px;text-align: center;background: #EFF6FF">联系电话</td>
        <td style="width: 350px;height: 15px;text-align: center  "><el-input  v-model="warehouse.phone" /></td>
        <td style="width: 250px;height: 15px;text-align: center ;background: #EFF6FF"  >项目联系人</td>
        <td style="width: 350px;height: 15px;text-align: center   "><el-input  v-model="warehouse.contact" /></td>
      </tr>
      <tr>
        <td>备注</td>
        <td colspan="3"><el-input  v-model="warehouse.description" /></td>

      </tr>
      <tr>
        <td colspan="4" style="background:#EFF6FF ">
          <el-button @click="updateWarehouseSummit" type="primary"  style="margin-top: 1%;margin-bottom: 1%" >确认修改</el-button>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
</template>

<style scoped lang="scss">
.bread-container {
  padding: 25px 10px;
  margin-left: 10px;
}


.divTable {
  position: static;
  top: 150px;
  bottom: 0;
  left: 300px;
  right: 0;
  margin: auto;
}


table, td,tr{
  border: 1px solid #44a8da;
  text-align: center;
  border-spacing: 0;
  border-collapse: collapse;
  height: 45px;
}

.tableTitle{

  border-right: 0 none;
  border-left: 0 none;
  text-align: center;
  font-size: large;
  font-weight: bold;
}

.demo-image__error .image-slot {
  font-size: 30px;
}
.demo-image__error .image-slot .el-icon {
  font-size: 30px;
}
.demo-image__error .el-image {
  width: 100%;
  height: 200px;
}

.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>